package org.exhaust.framework.net.cmpp20.handler;

import io.netty.channel.ChannelHandlerContext;
import org.exhaust.framework.net.cmpp20.protocol.CMPPActiveTest;
import org.exhaust.framework.net.cmpp20.protocol.CMPPActiveTestResp;
import org.exhaust.framework.net.cmpp20.protocol.CMPPBody;
import org.exhaust.framework.net.cmpp20.protocol.CMPPMessage;
import org.exhaust.framework.net.cmpp20.protocol.client.CMPPConnect;
import org.exhaust.framework.net.cmpp20.protocol.server.*;
import org.exhaust.framework.net.common.protocol.handler.BusinessDataHandler;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CMPPMessageHandler extends BusinessDataHandler<CMPPMessage> {

    private final Map<Class<? extends CMPPBody>,CMPPBodyHandler> HANDLER_MAP = new ConcurrentHashMap<>();

    @Override
    public void handleMsg(ChannelHandlerContext ctx, CMPPMessage packet) {
        Class<? extends CMPPBody> clazz = packet.getBody().getClass();
        HANDLER_MAP.get(clazz).handleBodyMsg(ctx,packet.getHeader(),packet.getBody());
    }

    public void setBodyHandler(Class<? extends CMPPBody> bodyClazz,CMPPBodyHandler bodyHandler){
        HANDLER_MAP.put(bodyClazz,bodyHandler);
    }
}
